from django.template import Library
from django.urls import reverse
from web import  models
register = Library()

@register.inclusion_tag("inclusion/all_project_list.html")
def all_project(request):
     # 我创建的项目
     my_list = models.Project.objects.filter(creator=request.transaction.user)
     join_list = models.ProjectUser.objects.filter(user=request.transaction.user)

     return {"my":my_list,"join":join_list}

@register.inclusion_tag("inclusion/project_menum.html")
def project_menum(request):
     data_list = [
          {"title": "概览", "url": reverse("dashboard", kwargs={"project_id": request.manage.id})},
          {"title": "问题", "url": reverse("issues", kwargs={"project_id": request.manage.id})},
          {"title": "统计", "url": reverse("statcstics", kwargs={"project_id": request.manage.id})},
          {"title": "wiki", "url": reverse("wiki", kwargs={"project_id": request.manage.id})},
          {"title": "文件", "url": reverse("file", kwargs={"project_id": request.manage.id})},
          {"title": "配置", "url": reverse("setting", kwargs={"project_id": request.manage.id})},
     ]
     for item in data_list:
          if request.path_info.startswith(item["url"]):
               item['class'] = 'active'

     return {"data_list":data_list}